package com.inplaceedit.client.application;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.activity.shared.CachingActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.inplaceedit.client.activity.main.MainActivityMapper;
import com.inplaceedit.client.activity.menu.MenuActivityMapper;

public class Application implements EntryPoint {

	private final ApplicationInjector injector = GWT
			.create(ApplicationInjector.class);

	@Override
	public void onModuleLoad() {
		// Initialize an activity mapper for the menu panel
		final ActivityMapper menuActivityMapper = new CachingActivityMapper(
				new MenuActivityMapper(injector));
		final ActivityManager menuActivityManager = new ActivityManager(
				menuActivityMapper, injector.getEventBus());
		menuActivityManager.setDisplay(injector.getApplicationShell()
				.getMenuPanel());

		// Initialize an activity mapper for the main panel
		final ActivityMapper mainActivityMapper = new CachingActivityMapper(
				new MainActivityMapper(injector));
		final ActivityManager mainActivityManager = new ActivityManager(
				mainActivityMapper, injector.getEventBus());
		mainActivityManager.setDisplay(injector.getApplicationShell()
				.getMainPanel());

		// Display the application shell
		RootPanel.get().add(injector.getApplicationShell());

		// Go to the place matching the startup URL
		injector.getPlaceHistoryHandler().handleCurrentHistory();
	}
}
